<template>
	<view class="container999">
		<refresh :isTop="isTop" ref="refresh" :needVibrate="true" @isRefresh="isRefresh"></refresh>
		<navTopTT title="领福利" :showBack="true"></navTopTT>
		<scroll-view scroll-y="true" @scroll="scrollTop" @touchstart="refreshStart" @touchmove="refreshMove"
			@touchend="refreshEnd">
			<view class="block-box1" style="padding-top: 20rpx;">
				<view v-if="groupId" style="position: relative;">
					<image style="height: 216rpx;width: 700rpx;margin-bottom: 30rpx;"
						src="https://res.qiguoread.com/staticResources/fellow_townsman/image/jiaqun_fuliye.png" lazy-load
						mode="aspectFill"></image>
					<button class="content-btn" open-type="joinGroup" :data-is-half-page="true" :group-id="groupId"
						@click="handleJoinGroup"></button>
				</view>
				<view v-if="recommendObj.length > 0" v-for="(sectionItem, sectionIndex) in recommendObj"
					:key="sectionIndex">
					<ttStyleFive ref="ttStyleFive" v-if="sectionItem.styleType == 'STYLE_23'" :title="sectionItem.name"
						:list="sectionItem.contents"></ttStyleFive>
					<ttStyleFour ref="ttStyleFour" v-if="sectionItem.styleType == 'STYLE_19'" :title="sectionItem.name"
						:list="sectionItem.contents" />
					<mayFollow :title="sectionItem.name" :list="sectionItem.contents"
						v-if="sectionItem.styleType == 'STYLE_1'" ref="mayFollow"></mayFollow>
					<oneLikeTT v-if="sectionItem.styleType == 'STYLE_2'" :title="sectionItem.name"
						:list="sectionItem.contents" ref="oneLikeTT"></oneLikeTT>
					<ttStyleThree ref="ttStyleThree" v-if="sectionItem.styleType == 'STYLE_18'" :title="sectionItem.name"
						:list="sectionItem.contents" />
				</view>
			</view>
			<!-- <view style="height: 68rpx;"></view> -->
			<!-- 继续 -->
			<lastWatch :nowItem="historyList[0]" v-if="isFirstLoad && historyList.length === 1"></lastWatch>
		</scroll-view>
	</view>
</template>

<script>
import lastWatch from '../specialPage/lastWatch.vue';
import mayFollow from '../fx_xjc/components/mayFollow.vue';
import oneLikeTT from '../fx_xjc/components/oneLikeTT.vue';
import ttStyleThree from '../fx_xjc/components/ttStyleThree.vue';
import ttStyleFour from '../fx_xjc/components/ttStyleFour.vue';
import ttStyleFive from '../fx_xjc/components/ttStyleFive.vue';
import refresh from '../../components/refresh.vue';
export default {
	components: {
		lastWatch, mayFollow, oneLikeTT, ttStyleThree, ttStyleFour, ttStyleFive, refresh
	},
	props: {
		nowId: {
			type: String | Number,
			default: ''
		}
	},
	data() {
		return {
			recommendObj: {},
			scrollTopNum: 0,
			isFirstLoad: true,
			historyList: [],
			isTop: true,
			groupId: null, //群id
			statusBarHeight: uni.getSystemInfoSync()['statusBarHeight'] || 20, // 顶部高度状态栏
		};
	},

	async onShow() {
		// 切换刷新
		//#ifdef MP-TOUTIAO
		await this.$nextTick()
		this.reset()
		//#endif
	},
	async onLoad(e) {
		if (e && e.use) {
			this.geWriteOff()
		}
		this.$statis({
			action: 'VISIT',
			page: 'pages/benefits/benefit',
			position: 'pages/benefits/benefitP',
		})
	},
	methods: {
		async reset() {
			console.log('更新页面1')
			uni.showLoading({
				title: ''
			})
			this.getGroupInfo(5, 2)
			this.getHistory()
			await this.getIndexConfig()
			uni.hideLoading()
		},
		// 刷新touch监听
		refreshStart(e) {
			this.$refs.refresh.refreshStart(e);
		},
		refreshMove(e) {
			this.$refs.refresh.refreshMove(e);
		},
		refreshEnd(e) {
			this.$refs.refresh.refreshEnd(e);
		},
		isRefresh() {
			// this.getIndexConfig()
			this.reset()
			this.$refs.ttStyleFour && this.$refs.ttStyleFour[0].changeIndex()
			this.$refs.ttStyleFive && this.$refs.ttStyleFive[0].changeIndex()
			this.$refs.mayFollow && this.$refs.mayFollow[0].changeIndex()
		},
		scrollTop(e) {
			this.scrollTopNum = e.detail.scrollTop
			if (e.detail.scrollTop <= 40) this.isTop = true;
			else this.isTop = false;
		},
		toDetail(item) {
			console.log(item)
			if (!item.fakeId && !item.contentInfo.fakeId) return
			this.zwyRouter(`../video/video?fakeId=${item.fakeId || (item.contentInfo || {}).fakeId}&compilationId=${item.compilationId || (item.contentInfo || {}).compilationId}`);
		},
		getHistory() {
			this.zwyRequest({
				url: `/cdp/user_history/compilations?pageNum=1&pageSize=10`
			}).then(res => {
				if (res) {
					this.historyList = res;
					this.$forceUpdate();
				}
			});
		},
		// 获取首页配置
		async getIndexConfig() {
			try {
				let res = await this.zwyRequest({
					url: '/cdp/section_group',
					method: 'GET',
					data: {
						sectionGroupTypeValue: 10
					}
				})
				this.recommendObj = res
				this.$refs.refresh.endAfter(); //刷新结束调用
				getApp().globalData.needRefresh = false;

			} catch (error) {
				console.log(error)
			}
		},
		async getGroupInfo(num, diversionTarget) {
			let res = await this.zwyRequest({
				method: 'get',
				url: `/douYin/diversion?diversionScene=${num}&diversionTarget=${diversionTarget}`
			})
			if (res && res[0]) {
				this.taskId = res[0].id;
				this.groupId = res[0].groupId
				this.$statis({
					action: 'EXPOSURE',
					position: 'DY_DIVERSION_DY_GROUP/DY_DIVERSION_WELFARE_CAPSULE',
					taskId:this.taskId
				})
			}
		},
		handleJoinGroup(e) {
			//#ifdef MP-TOUTIAO
			setTimeout(() => {
				this.getGroupInfo(5, 2)
			}, 100)
			this.$statis({
				action: 'CLICK',
				position: 'DY_DIVERSION_DY_GROUP/DY_DIVERSION_WELFARE_CAPSULE',
				taskId:this.taskId
			})
			//#endif
			console.log(e, this.groupId, '回调信息')

		},
		// 核销
		geWriteOff() {
			this.zwyRequest({
				url: `/douYin/coupons/verification`
			}).then(res => {
				console.log(res.data.msg, '调用核销接口');
				if (res.data && res.data.code == 0) {
					uni.showToast({
						title: `${res.data.msg}`,
						icon: 'none'
					})
				}
			});
		},
	}
};
</script>

<style lang="scss" scoped>
.container999 {
	width: 100vw;
	font-size: 28rpx;
	min-height: 100vh;
	overflow: hidden;
	color: #6b8082;
	position: relative;
	background-color: #ffffff;
	/* #ifdef MP-TOUTIAO */
	background-color: #F5F5F5;
	/* #endif */
}

.nav {
	position: fixed;
	left: 0;
	top: 0;
	color: #000000;
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	justify-content: flex-start;
	font-size: 24rpx;
	background-color: #ffffff;
	z-index: 996;
}

.navTopBox {
	font-size: 34rpx;
	font-weight: bold;
	// border-bottom: 1px solid #f2f3f4;
	width: 92vw;
	line-height: 104rpx;
	display: flex;
	align-items: center;
	height: 104rpx;
	// #ifdef MP-KUAISHOU
	margin: auto;
	justify-content: center;
	//  #endif
	// #ifdef MP-TOUTIAO
	margin: 0 0 0 100rpx;
	//  #endif
}

.content-btn {
	position: absolute;
	width: 100%;
	bottom: 26rpx;
	left: 50%;
	transform: translateX(-50%);
	height: 216rpx;
	width: 710rpx;
	opacity: 0;
	// width: 240rpx;
	// height: 57rpx;
	// background: url('https://res.qiguoread.com/staticResources/fellow_townsman/image/jiaqun_home_btn.png');
	// background-size: 100% 100%;
}

.block-box1 {
	display: flex;
	flex-direction: column;
	width: 710rpx;
	// padding: 31rpx;
	// border-radius: 30rpx;
	margin: 0 auto;

}



page {
	background-color: white !important;
	border-top: 1rpx solid #f6f6f6;
}
</style>
